namespace OneWorks.Utils.FluentData
{
    using System;
    using System.Data;

    internal class QueryDataTableHandler<TEntity> : IQueryTypeHandler<TEntity>
    {
        private readonly DbCommandData _data;

        public bool IterateDataReader { get { return false; } }

        public QueryDataTableHandler(DbCommandData data)
        {
            this._data = data;
        }

        public object HandleType(Action<TEntity, IDataReader> customMapperReader, Action<TEntity, dynamic> customMapperDynamic)
        {
            var dataTable = new DataTable();
            dataTable.Load(this._data.Reader.InnerReader, LoadOption.OverwriteChanges);
			
            return dataTable;
        }
    }
}